<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="部门" prop="department">
      <el-input v-model="dataForm.department" placeholder="部门"></el-input>
    </el-form-item>
    <el-form-item label="机构名称" prop="institutionname">
      <el-input v-model="dataForm.institutionname" placeholder="机构名称"></el-input>
    </el-form-item>
    <el-form-item label="任务详情" prop="missiondetails">
      <el-input v-model="dataForm.missiondetails" placeholder="任务详情"></el-input>
    </el-form-item>
    <el-form-item label="产品分类" prop="productclassification">
      <el-input v-model="dataForm.productclassification" placeholder="产品分类"></el-input>
    </el-form-item>
    <el-form-item label="任务成员" prop="taskmembers">
      <el-input v-model="dataForm.taskmembers" placeholder="任务成员"></el-input>
    </el-form-item>
    <el-form-item label="任务级别" prop="tasklevel">
      <el-input v-model="dataForm.tasklevel" placeholder="任务级别"></el-input>
    </el-form-item>
    <el-form-item label="任务状态" prop="taskstatus">
      <el-input v-model="dataForm.taskstatus" placeholder="任务状态"></el-input>
    </el-form-item>
    <el-form-item label="任务类型" prop="task type">
      <el-input v-model="dataForm.task type" placeholder="任务类型"></el-input>
    </el-form-item>
    <el-form-item label="任务附件" prop="task attachment">
      <el-input v-model="dataForm.task attachment" placeholder="任务附件"></el-input>
    </el-form-item>
    <el-form-item label="任务说明" prop="mission statement">
      <el-input v-model="dataForm.mission statement" placeholder="任务说明"></el-input>
    </el-form-item>
    <el-form-item label="发布人" prop="publisher">
      <el-input v-model="dataForm.publisher" placeholder="发布人"></el-input>
    </el-form-item>
    <el-form-item label="联系人" prop="contacts">
      <el-input v-model="dataForm.contacts" placeholder="联系人"></el-input>
    </el-form-item>
    <el-form-item label="联系电话" prop="contact number">
      <el-input v-model="dataForm.contact number" placeholder="联系电话"></el-input>
    </el-form-item>
    <el-form-item label="联系QQ" prop="contact qq">
      <el-input v-model="dataForm.contact qq" placeholder="联系QQ"></el-input>
    </el-form-item>
    <el-form-item label="开始日期" prop="start date">
      <el-input v-model="dataForm.start date" placeholder="开始日期"></el-input>
    </el-form-item>
    <el-form-item label="结束日期" prop="end date">
      <el-input v-model="dataForm.end date" placeholder="结束日期"></el-input>
    </el-form-item>
    <el-form-item label="申请加急状态" prop="urgent status of application">
      <el-input v-model="dataForm.urgent status of application" placeholder="申请加急状态"></el-input>
    </el-form-item>
    <el-form-item label="到期天数" prop="due days">
      <el-input v-model="dataForm.due days" placeholder="到期天数"></el-input>
    </el-form-item>
    <el-form-item label="上传附件" prop="upload attachment">
      <el-input v-model="dataForm.upload attachment" placeholder="上传附件"></el-input>
    </el-form-item>
    <el-form-item label="发布日期" prop="dateofissue">
      <el-input v-model="dataForm.dateofissue" placeholder="发布日期"></el-input>
    </el-form-item>
    <el-form-item label="期望完成日期" prop="expectedcompletiondate">
      <el-input v-model="dataForm.expectedcompletiondate" placeholder="期望完成日期"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          department: '',
          institutionname: '',
          missiondetails: '',
          productclassification: '',
          taskmembers: '',
          tasklevel: '',
          taskstatus: '',
          task type: '',
          task attachment: '',
          mission statement: '',
          publisher: '',
          contacts: '',
          contact number: '',
          contact qq: '',
          start date: '',
          end date: '',
          urgent status of application: '',
          due days: '',
          upload attachment: '',
          dateofissue: '',
          expectedcompletiondate: ''
        },
        dataRule: {
          department: [
            { required: true, message: '部门不能为空', trigger: 'blur' }
          ],
          institutionname: [
            { required: true, message: '机构名称不能为空', trigger: 'blur' }
          ],
          missiondetails: [
            { required: true, message: '任务详情不能为空', trigger: 'blur' }
          ],
          productclassification: [
            { required: true, message: '产品分类不能为空', trigger: 'blur' }
          ],
          taskmembers: [
            { required: true, message: '任务成员不能为空', trigger: 'blur' }
          ],
          tasklevel: [
            { required: true, message: '任务级别不能为空', trigger: 'blur' }
          ],
          taskstatus: [
            { required: true, message: '任务状态不能为空', trigger: 'blur' }
          ],
          task type: [
            { required: true, message: '任务类型不能为空', trigger: 'blur' }
          ],
          task attachment: [
            { required: true, message: '任务附件不能为空', trigger: 'blur' }
          ],
          mission statement: [
            { required: true, message: '任务说明不能为空', trigger: 'blur' }
          ],
          publisher: [
            { required: true, message: '发布人不能为空', trigger: 'blur' }
          ],
          contacts: [
            { required: true, message: '联系人不能为空', trigger: 'blur' }
          ],
          contact number: [
            { required: true, message: '联系电话不能为空', trigger: 'blur' }
          ],
          contact qq: [
            { required: true, message: '联系QQ不能为空', trigger: 'blur' }
          ],
          start date: [
            { required: true, message: '开始日期不能为空', trigger: 'blur' }
          ],
          end date: [
            { required: true, message: '结束日期不能为空', trigger: 'blur' }
          ],
          urgent status of application: [
            { required: true, message: '申请加急状态不能为空', trigger: 'blur' }
          ],
          due days: [
            { required: true, message: '到期天数不能为空', trigger: 'blur' }
          ],
          upload attachment: [
            { required: true, message: '上传附件不能为空', trigger: 'blur' }
          ],
          dateofissue: [
            { required: true, message: '发布日期不能为空', trigger: 'blur' }
          ],
          expectedcompletiondate: [
            { required: true, message: '期望完成日期不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/com.emp/tasklist/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.department = data.tasklist.department
                this.dataForm.institutionname = data.tasklist.institutionname
                this.dataForm.missiondetails = data.tasklist.missiondetails
                this.dataForm.productclassification = data.tasklist.productclassification
                this.dataForm.taskmembers = data.tasklist.taskmembers
                this.dataForm.tasklevel = data.tasklist.tasklevel
                this.dataForm.taskstatus = data.tasklist.taskstatus
                this.dataForm.task type = data.tasklist.task type
                this.dataForm.task attachment = data.tasklist.task attachment
                this.dataForm.mission statement = data.tasklist.mission statement
                this.dataForm.publisher = data.tasklist.publisher
                this.dataForm.contacts = data.tasklist.contacts
                this.dataForm.contact number = data.tasklist.contact number
                this.dataForm.contact qq = data.tasklist.contact qq
                this.dataForm.start date = data.tasklist.start date
                this.dataForm.end date = data.tasklist.end date
                this.dataForm.urgent status of application = data.tasklist.urgent status of application
                this.dataForm.due days = data.tasklist.due days
                this.dataForm.upload attachment = data.tasklist.upload attachment
                this.dataForm.dateofissue = data.tasklist.dateofissue
                this.dataForm.expectedcompletiondate = data.tasklist.expectedcompletiondate
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/com.emp/tasklist/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'department': this.dataForm.department,
                'institutionname': this.dataForm.institutionname,
                'missiondetails': this.dataForm.missiondetails,
                'productclassification': this.dataForm.productclassification,
                'taskmembers': this.dataForm.taskmembers,
                'tasklevel': this.dataForm.tasklevel,
                'taskstatus': this.dataForm.taskstatus,
                'task type': this.dataForm.task type,
                'task attachment': this.dataForm.task attachment,
                'mission statement': this.dataForm.mission statement,
                'publisher': this.dataForm.publisher,
                'contacts': this.dataForm.contacts,
                'contact number': this.dataForm.contact number,
                'contact qq': this.dataForm.contact qq,
                'start date': this.dataForm.start date,
                'end date': this.dataForm.end date,
                'urgent status of application': this.dataForm.urgent status of application,
                'due days': this.dataForm.due days,
                'upload attachment': this.dataForm.upload attachment,
                'dateofissue': this.dataForm.dateofissue,
                'expectedcompletiondate': this.dataForm.expectedcompletiondate
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
